package cn.com.qiancheng.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import cn.com.qiancheng.util.DbUtil;

public class PasswordDao {
	public int passUpdate(int stuId, String newP, int role) {
		int i = 0;
		switch(role){
		case 1:
			try {
				Connection con = DbUtil.openConnection();
				String sql = "Update t_students SET stu_password = ?,l_num = 1 WHERE stu_id = ?";
				PreparedStatement stat = con.prepareStatement(sql);
				stat.setString(1, newP);
				stat.setInt(2, stuId);
				i = stat.executeUpdate();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} finally {
				try {
					DbUtil.closeConnection();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			break;
		case 2:
			try {
				Connection con = DbUtil.openConnection();
				String sql = "Update t_admin SET ad_password = ? WHERE ad_id = ?";
				PreparedStatement stat = con.prepareStatement(sql);
				stat.setString(1, newP);
				stat.setInt(2, stuId);
				i = stat.executeUpdate();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} finally {
				try {
					DbUtil.closeConnection();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			break;
		}
		
		return i;
	}
	
	
}
